package cn.xuguowen.common;

import cn.xuguowen.bean.Result;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * ClassName: GlobalExceptionHandler
 * Package: cn.xuguowen.common
 * Description:
 *
 * @Author 徐国文
 * @Create 2023/2/26 14:48
 * @Version 1.0
 */
@RestControllerAdvice
public class GlobalExceptionHandler {

    @ExceptionHandler(RuntimeException.class)
    public Result runTimeException(RuntimeException e) {
        // 当然了可以将异常记录到文件中。集成logback
        e.printStackTrace();
        e.getMessage();
        return Result.fail();
    }

    @ExceptionHandler(Exception.class)
    public Result exception(Exception e) {
        // 当然了可以将异常记录到文件中。集成logback
        e.printStackTrace();
        e.getMessage();
        return Result.fail();
    }
}
